package org.socialresume.client.mvp.view;

import java.util.Collection;
import java.util.Map;

import org.socialresume.client.model.Feed;
import org.socialresume.client.model.FeedTypeEnum;
import org.socialresume.client.model.TwitterFeed;
import org.socialresume.client.mvp.presenter.MenuPresenter.Display;
import org.socialresume.client.mvp.view.widget.FeedWidget;

import com.google.gwt.event.logical.shared.HasSelectionHandlers;
import com.google.gwt.event.logical.shared.SelectionEvent;
import com.google.gwt.event.logical.shared.SelectionHandler;
import com.google.gwt.event.shared.HandlerRegistration;
import com.google.gwt.user.client.ui.HasHorizontalAlignment;
import com.google.gwt.user.client.ui.HasVerticalAlignment;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.google.gwt.user.client.ui.Widget;

public class MenuDisplayImpl extends VerticalPanel implements Display,HasSelectionHandlers<Feed>{

	private FeedsPanel feeds;

	public MenuDisplayImpl() {
		//Mock
		feeds = new FeedsPanel(false);
		
		feeds.addFeed(new Feed(FeedTypeEnum.LINKEDIN,"http://www.ncl.ac.uk/alumni/assets/images/linkedin.png","LinkedIn", "LinkedIn is in !!","http://www.linkedin.com/in/ludovicmeurillon"));
		feeds.addFeed(new TwitterFeed("LudoMeurillon","Twitter","Twiter is in !!"));
		feeds.addFeed(new Feed(FeedTypeEnum.RSS		,"http://www.growlforwindows.com/gfw/images/plugins/googlereader.png", "Google Reader","Googler Reader is in!!","http://www.google.com/reader/shared/ludovic.meurillon"));
		feeds.addFeed(new Feed(FeedTypeEnum.FACEBOOK,"http://anar.zone.free.fr/images/facebook.png","Facebook", "Facebook is in !!","http://facebook.fr/ludovic.meurillon"));
		
		Map<String, FeedWidget> widgets = feeds.getFeedsWidgets();
		for (String key : widgets.keySet()) {
			widgets.get(key).addSelectionHandler(new SelectionHandler<Feed>() {
				@Override
				public void onSelection(SelectionEvent<Feed> event) {
					SelectionEvent.fire(MenuDisplayImpl.this, event.getSelectedItem());
				}
			});
		}
		
		add(feeds);
		setHorizontalAlignment(HasHorizontalAlignment.ALIGN_LEFT);
		setVerticalAlignment(HasVerticalAlignment.ALIGN_MIDDLE);
	}
	
	@Override
	public Widget asWidget() {
		return this;
	}

	@Override
	public HasSelectionHandlers<Feed> getHasFeedSelectHandlers() {
		return this;
	}

	@Override
	public HandlerRegistration addSelectionHandler(SelectionHandler<Feed> handler) {
		return addHandler(handler, SelectionEvent.getType());
	}

	@Override
	public void setFeeds(Collection<Feed> feeds) {
		// TODO Auto-generated method stub
		
	}
}
